package cn.tedu.hm.controller;

import cn.tedu.hm.pojo.dto.OrderMakeNewDTO;
import cn.tedu.hm.pojo.dto.ServiceAddNewDTO;
import cn.tedu.hm.pojo.vo.OrderListItemVO;
import cn.tedu.hm.pojo.vo.SalaryShowListItemVO;
import cn.tedu.hm.pojo.vo.ServiceListItemVO;
import cn.tedu.hm.service.ISalaryShowService;
import cn.tedu.hm.service.IServiceService;
import cn.tedu.hm.wep.JsonPage;
import cn.tedu.hm.wep.JsonResult;
import cn.tedu.hm.wep.WebConsts;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author tj41h
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/service/")
@Api(tags="11. 服务列表模块")
@Transactional
public class ServiceController {

    @Autowired
    private IServiceService serviceService;


    @PostMapping("new")
    @ApiOperation("新增服务")
    @ApiOperationSupport(order = 410)
    public JsonResult<Void> New(ServiceAddNewDTO serviceAddNewDTO){
        log.debug("开始执行生成服务的请求，参数为{}",serviceAddNewDTO);
       serviceService.add(serviceAddNewDTO);
        return JsonResult.ok();
    }



    @GetMapping("")
    @ApiOperation("查询服务列表")
    @ApiOperationSupport(order = 420)
    @ApiImplicitParams({
            @ApiImplicitParam(value = "页码",name="page",example = "1"),
            @ApiImplicitParam(value = "每页条数",name="pageSize",example = "10")
    })
    public JsonResult<JsonPage<ServiceListItemVO>> list(
            @RequestParam(required = false,defaultValue = WebConsts.DEFAULT_PAGE)
                                                         Integer page,
            @RequestParam(required = false,defaultValue = WebConsts.DEFAULT_PAGE_SIZE)
                                                         Integer pageSize) {
        log.debug("开始处理【查询服务列表】的请求，参数:{},{}",page,pageSize);
        JsonPage<ServiceListItemVO> list = serviceService.list(page, pageSize);
        return JsonResult.ok(list);
    }

    @GetMapping("/selectByName")
    @ApiOperation("根据名字模糊查询服务列表")
    @ApiOperationSupport(order = 430)
    @ApiImplicitParams({
            @ApiImplicitParam(value = "房间号",name = "name"),
            @ApiImplicitParam(value = "页码",name="page",example = "1"),
            @ApiImplicitParam(value = "每页条数",name="pageSize",example = "10")
    })
    public JsonResult<JsonPage<ServiceListItemVO>> selectByName(
            @RequestParam()
            String name,
            @RequestParam(required = false,defaultValue = WebConsts.DEFAULT_PAGE)
            Integer page,
            @RequestParam(required = false,defaultValue = WebConsts.DEFAULT_PAGE_SIZE)
            Integer pageSize){
        JsonPage<ServiceListItemVO> list = serviceService.getListByName(name, page, pageSize);
        return JsonResult.ok(list);
    }

    @PostMapping("/{id:[0-9]+}/delete")
    @ApiOperation("根据ID删除服务")
    @ApiOperationSupport(order = 440)
    @ApiImplicitParam(name = "id", value = "房间ID", required = true, dataType = "long")
    public JsonResult<Void> delete(@PathVariable @Range(min = 1, message = "请提交有效的ID值！") Long id) {
        log.debug("开始处理【根据ID删除服务】的请求，参数：{}", id);
        serviceService.delete(id);
        return JsonResult.ok();
    }
}
